<?xml version="1.0" encoding="utf-8" ?>
<taskrunner name="databases" version="1.0" date="2008-10-30" maxthreads="1">

  <!-- checks installed version. -->

  <includes>
    <file name="vida.install.settings.xml" />
  </includes>

  <tasks>

    <task name="stop.sqlexpress.service" typename="@WindowsServiceCommand">
      <description>
        stops sql express.
      </description>
      <dependencies list=""/>
      <parameters>
        <parameter name="server.name" value=""/>
        <parameter name="service.name" value="MSSQL$${sqlserver.instance.name}"/>
        <parameter name="command" value="stop"/>
        <parameter name="throwException" value="false"/>
      </parameters>
    </task>


    <task name="unzip.databases">
      <description>
        Unzips the database files.
      </description>
      <dependencies list="stop.sqlexpress.service"/>
      <subtasks filename="vida.unzip.databases.xml"/>
    </task>

    <task name="change.attributes.on.db" typename="@CommandLine">

      <description>
        removes the attribute read-only on all files in the dvdinput directory.
      </description>
      <dependencies list="unzip.databases"/>
      <parameters>
        <parameter name="arguments" value="attrib -r /s"/>
        <parameter name="workingdirectory" value="${target.db.dir}"/>
        <parameter name="useCmdExe" value="true"/>
      </parameters>
    </task>


    <task name="start.sqlexpress.service" typename="@WindowsServiceCommand">
      <description>
        starts sql express instance.
      </description>
      <dependencies list="change.attributes.on.db"/>
      <parameters>
        <parameter name="server.name" value=""/>
        <parameter name="service.name" value="MSSQL$${sqlserver.instance.name}"/>
        <parameter name="command" value="start"/>
        <parameter name="throwException" value="false"/>
      </parameters>
    </task>

    <task name="start.sqlexpress.browser" typename="@WindowsServiceCommand" retry="3">
      <dependencies list="start.sqlexpress.service"/>
      <parameters>
        <parameter name="server.name" value=""/>
        <parameter name="service.name" value="Sql Server Browser"/>
        <parameter name="command" value="start"/>
      </parameters>
    </task>

    <task name="SetAccessRule" typename="@AccessControl">
      <description>
        Make sure Sql Server local account has the right to attach databases from the
        database folder.
      </description>
      <dependencies list="change.attributes.on.db"/>
      <parameters>
        <parameter name="user" value="${sqlserver.service.account}"/>
        <parameter name="folder" value="${target.db.dir}"/>
      </parameters>
    </task>

    <task name="attach.databases">
      <description>
        Attaches databases.
      </description>
      <dependencies list="change.attributes.on.db,SetAccessRule,start.sqlexpress.service"/>
      <subtasks filename="vida.attach.databases.xml"/>
    </task>

    <task name="add.database.users">
      <description>
        Adds the required user names to the databases.
      </description>
      <dependencies list="attach.databases"/>
      <subtasks filename="vida.add.database.users.xml"/>
    </task>

    <task name="update.databases">
      <description>
        Updates AccessServer,DiagSwdlSession and BaseData
        with the lates changes
      </description>
      <dependencies list="attach.databases"/>
      <subtasks filename="vida.update.databases.xml"/>
    </task>

    <task name="postinstall">
      <description>
        Runs sql scripts in order to add necessary info to accessserver.
      </description>
      <dependencies list="update.databases"/>
      <subtasks filename="vida.postinstall.xml"/>
    </task>

  </tasks>

</taskrunner>